﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;

public partial class Agent_PostAddress : AgentPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Delete();
        Agent_Account_Menu.SelectMenu = 4;
        if (!IsPostBack)
            BindData();
    }
    protected void BindData()
    {
        List<MatchIns.Model.TPostAddress> ds = new MatchIns.BLL.TPostAddress().GetList();
        ViewState["addressCount"] = ds.Count.ToString();
        if (ds.Count == 0)
            rpAddress.FooterTemplate = new EmptyData("<tr><td colspan='5' height='50'>还未填写收单地址。</td></table>");
        rpAddress.DataSource = ds;
        rpAddress.DataBind();
        //rpAddress.FooterTemplate = "";
    }

    protected void Delete()
    {
        string id = Request.QueryString["id"];
        if (id == null) return;
        new MatchIns.BLL.TPostAddress().Delete(int.Parse(id), UserInfo.UserID);
    }
    protected void save_Click(object sender, EventArgs e)
    {
        MatchIns.Model.TPostAddress model = new MatchIns.Model.TPostAddress();
        model.Name = name.Text.Trim();
        model.UserID = UserInfo.UserID;
        model.ProvinceID = Area1.ProviceId;
        model.CityID = Area1.CityId;
        model.DistrictID = Area1.DistrictId;
        model.Address = address.Value;
        model.ZipCode = zipcode.Text;
        model.Tel = tel.Text;
        model.Mobile = mobilePhone.Text;
        model.IsDefault = (ViewState["addressCount"].ToString() == "0");
        model.AddTime = DateTime.Now;
        new MatchIns.BLL.TPostAddress().Add(model);
        Alert("收货地址添加成功.");
        Location("PostAddress.aspx");
    }
}
